global class UpdateContactFromPortalUser {
    @future
    public static void updateContacts(String userId) {
        User u = [select ContactId,Email,FirstName,LastName,Title,Phone,Fax,MobilePhone,Street,City,State,PostalCode,Country 
                    from User
                    where Id=:userId];
                
        if (u!=null && u.ContactId!=null) {
            Contact c = new Contact(Id=u.ContactId);
            
            c.MailingStreet=u.Street;
            c.MailingCity=u.City;
            c.MailingState=u.State;
            c.MailingPostalCode=u.PostalCode;
            c.MailingCountry=u.Country;
            c.Phone = u.Phone;
            c.Fax=u.Fax;
            c.MobilePhone=u.MobilePhone;
            c.Email = u.Email;
            c.FirstName=u.FirstName;
            c.LastName=u.LastName;
            c.Title=u.Title;
            update c;
        }
    }
    
    static testMethod void testUpdateContacts() {   
        Test.startTest();   
        User u = [select Id,ContactId,FirstName from User where ContactId<>'' limit 1]; 
        
        u.FirstName='Bar';
        update u;
        
        Test.stopTest();
        
        Contact c = [select FirstName from Contact where Id=:u.ContactId];
        System.assertEquals(c.FirstName,u.FirstName);
    }
}